<template>
	<div v-loading="loading">
		<div class="title1">
			<div>
				<span class="h1">基础管理</span>
				<span class="h2">操作员</span>
			</div>
		</div>
		<div class="con">
			<div class="search clearfix" style="margin-top: 10px;">
				<el-button type="primary" @click="addust()">新建操作员</el-button>
				<el-button type="primary" @click="addrol()">新建角色</el-button>
				<div style="width:240px;float:right;position: relative; margin-top: 10px;">
					<el-input v-model="input1" placeholder="请输入..."></el-input>
					<i class="el-icon-search" style="position: absolute; width:40px;height:36px;right:0;top:0;color:#000;text-align:center;line-height:36px" @click="searcj()"></i>
				</div>
			</div>
			<div style="margin-top: 10px;padding-bottom: 100px;overflow: auto">
				<el-table ref="tableData" :data="tableData" highlight-current-row style="width: 100%">
					<el-table-column type="index" width="60">
					</el-table-column>
					<el-table-column prop="Login" label="用户名">
					</el-table-column>
					<el-table-column prop="CNName" label="姓名">
					</el-table-column>
					<el-table-column prop="Tel" label="电话">
					</el-table-column>
					<el-table-column prop="StatusStr" label="状态">
					</el-table-column>
					<el-table-column prop="LoginType" label="用户类型">
						<template slot-scope="scope">
							<span v-if="scope.row.LoginType==1">操作员</span>
							<span v-else>业务员</span>
						</template>
					</el-table-column>
					<el-table-column prop="address" label="操作" width="230">
						<template slot-scope="scope">
							<el-dropdown trigger="click">
								<span class="el-dropdown-link"><el-button type="primary">操作<i class="el-icon-arrow-down el-icon--right"></i></el-button></span>
								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item>
										<el-button size="small" type="primary" @click="modify(scope.row.LoginType,scope.row.CNName,scope.row.Login,scope.row.Status,scope.row.Tel,scope.row.BuisnessID)">修改</el-button>
									</el-dropdown-item>
									<el-dropdown-item>
										<el-button size="small" type="success"  @click="lock(scope.$index, scope.row.Login,scope.row.Status)" v-if="scope.row.Status">解锁</el-button>
										<el-button size="small" type="success" @click="lock(scope.$index, scope.row.Login,scope.row.Status)" v-else>锁定</el-button>
									</el-dropdown-item>
									<el-dropdown-item>
										<el-button size="small"  type="danger" @click="deleteRow(scope.$index,scope.row.Login)">删除</el-button>
									</el-dropdown-item>
									<el-dropdown-item>
										<el-button size="small" type="info" @click="fnReset(scope.row.Login)">重置</el-button>
									</el-dropdown-item>
									<el-dropdown-item>
										<el-button size="small" type="primary" @click.native.prevent="setrole(scope.row.Login)">权限</el-button>
									</el-dropdown-item>
									<el-dropdown-item>
										<el-button size="small" type="warning" @click.native.prevent="Unbundling(scope.$index, scope.row.Login)">解绑</el-button>
									</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
						</template>
					</el-table-column>
				</el-table>
				<div style="float: right; margin-top: 10px;margin-right: 5px; height: 32px;">
					<el-pagination  :current-page="pageindex" @current-change="handleCurrentChange" layout="prev, pager, next" :total="leng">
					</el-pagination>
				</div>
			</div>
		</div>
		<div class="mark1" v-if="dialogVisible">
			<el-dialog title="操作员管理" :visible.sync="dialogVisible" size="tiny">
				<el-form ref="form" :model="form" label-width="80px">
					<el-form-item label="姓名">
						<el-input v-model="form.name"></el-input>
					</el-form-item>
					<el-form-item label="用户名">
						<el-input v-model="form.username"></el-input>
					</el-form-item>
					<el-form-item label="密码">
						<el-input v-model="form.pass" type="password"></el-input>
					</el-form-item>
					<el-form-item label="验证密码">
						<el-input v-model="form.pwd" type="password"></el-input>
					</el-form-item>
					<el-form-item label="联系电话">
						<el-input v-model="form.tel"></el-input>
					</el-form-item>
					<el-form-item label="用户类型">
						<el-radio-group v-model="radio" size="small" @change="chang()">
					      <el-radio label="1">操作员</el-radio>
					      <el-radio label="2">销售人员</el-radio>
					    </el-radio-group>
				    </el-form-item>
					<el-form-item label="业务员" v-if="usetype">
						<el-select v-model="sales" clearable filterable placeholder="请选择" style="width: 100%;" >
							<el-option v-for="item in ExtDics" :key="item.value" :label="item.lable" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
					<el-upload style="text-align: center;"
					  class="upload-demo"
					  ref="upload"
					  :action="host"
					  :on-preview="handlePreview"
					  :on-remove="handleRemove"
					  :file-list="fileList"
					  :onError="uploadError"
					  :limit="1"
					  :onSuccess="uploadSuccess"
					  :auto-upload="false">
					  <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
					  <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传文件</el-button>
					  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
					</el-upload>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="quxia()">取 消</el-button>
					<el-button type="primary" @click="newUere()">确 定</el-button>
				</span>
			</el-dialog>
		</div>

		<div class="mark5" v-if="mark5">
			<el-dialog title="修改操作员" :visible.sync="mark5" size="tiny">
				<el-form ref="form" :model="form" label-width="80px">
					<el-form-item label="姓名">
						<el-input v-model="form.name"></el-input>
					</el-form-item>
					<el-form-item label="用户名">
						<el-input v-model="form.username" :disabled="true"></el-input>
					</el-form-item>
					<el-form-item label="密码">
						<el-input v-model="form.pass" type="password"></el-input>
					</el-form-item>
					<el-form-item label="联系电话">
						<el-input v-model="form.tel"></el-input>
					</el-form-item>
					<el-form-item label="用户类型">
						<el-radio-group v-model="radio" size="small" @change="chang()">
					      <el-radio label="1">操作员</el-radio>
					      <el-radio label="2">销售人员</el-radio>
					    </el-radio-group>
				    </el-form-item>
					<el-form-item label="业务员" v-if="usetype">
						<el-select v-model="sales" filterable placeholder="请选择" style="width: 100%;">
							<el-option v-for="item in ExtDics" :key="item.value" :label="item.lable" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
					<el-upload style="text-align: center;"
					  class="upload-demo"
					  ref="upload"
					  :action="host"
					  :on-preview="handlePreview"
					  :on-remove="handleRemove"
					  :file-list="fileList"
					  :onError="uploadError"
					  limit="1"
					  :onSuccess="uploadSuccess"
					  :auto-upload="false">
					  <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
					  <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传文件</el-button>
					  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
					</el-upload>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="quxia()">取 消</el-button>
					<el-button type="primary" @click="updateuser()">确 定</el-button>
				</span>
			</el-dialog>
		</div>

		<div class="mark2" v-if="Mark2">
			<el-dialog title="新建角色" :visible.sync="Mark2" size="tiny">
				<el-row :gutter="20">
					<el-col :span="4" style="text-align: center; line-height: 36px;"><span>角色名：</span></el-col>
					<el-col :span="16">
						<el-input v-model="role" placeholder="请输入内容"></el-input>
					</el-col>
					<el-col :span="4">
						<el-button type="primary" @click="addRole()">添加</el-button>
					</el-col>
				</el-row>
				<el-row :gutter="20" style="margin-top: 20px;">
					<el-col :span="7">
						<div class="qxleft">
							<h3 class="rowl">角色</h3>
							<div style="height: 300px;overflow:auto;" id="jiaose">
								<button type="button" class="list-group-item" :value="item.ID" ref="name" v-for="(item,index) in roleList" @click="fnJur(item.ID)">{{item.RoleName}}</button>
							</div>
						</div>
					</el-col>
					<el-col :span="17" style="overflow: auto; height: 341px;">
						<div class="panel">
							<div class="qxtop">
								<h3 style="float: left;">权限配置</h3>
								<el-button type="danger" style="float: right;" @click="delUse()">删除</el-button>
							</div>
							<div class="qxtype">
								<div v-for="items in authlist">
									<div class="qxtype-title">{{items.GroupName}}</div>
									<div>
										<div class="checkbox c-checkbox needsclick">
											<el-checkbox-group v-model="item.isExists" v-for="item in items.ItemList" :key="item.id" class="divlist">
												<el-checkbox :label="item.ID" name="check" :value="item.ID" :checked="item.isExists">{{item.ItemName}}</el-checkbox>
											</el-checkbox-group>
										</div>
									</div>
								</div>
							</div>
						</div>
					</el-col>
				</el-row>
				<span slot="footer" class="dialog-footer">
					<el-button @click="Mark()">取 消</el-button>
					<el-button type="primary" @click="autl()">确 定</el-button>
				</span>
			</el-dialog>
		</div>

		<div class="mark3" v-if="Mark3">
			<el-dialog title="重置密码" :visible.sync="Mark3" size="tiny" :before-close="handleClose">
				<el-form ref="formInline" :model="formInline" label-width="100px">
					<el-form-item label="新密码：">
						<el-input v-model="formInline.pwd" type="password" placeholder=""></el-input>
					</el-form-item>
					<el-form-item label="密码确认：">
						<el-input v-model="formInline.oldpwd" type="password" placeholder=""></el-input>
					</el-form-item>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="quxia()">取 消</el-button>
					<el-button type="primary" @click="ModiPwd()">确 定</el-button>
				</span>
			</el-dialog>
		</div>
		<div class="mark4" v-if="mark4">
			<el-dialog title="权限配置" :visible.sync="mark4" size="tiny" :before-close="handleClose">
				<el-form ref="qxpz" :model="qxpz" label-width="100px">
					<el-form-item label="操作员：">
						<el-input v-model="qxpz.login" placeholder="" :disabled="true"></el-input>
					</el-form-item>
				</el-form>
				<div class="qxpzbox">
					<p class="qx-title">角色</p>
					<div>
						<p class="qx-title" v-for="item in roleList">
							<el-checkbox-group v-model="item.isExists">
								<el-checkbox :label="item.ID" name="row" :value="item.ID" :checked="item.isExists">{{item.RoleName}}</el-checkbox>
							</el-checkbox-group>
						</p>
					</div>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="fnCancel()">取 消</el-button>
					<el-button type="primary" @click="fnSubRole()">确 定</el-button>
				</span>
			</el-dialog>
		</div>
	</div>
</template>

<script>
	import api from '../../kits/api.js';
	export default {
		name: 'Operator',
		data() {
			return {
				Page1:1, 
 				pagesize:10, 
				host:"",
				fileList:[],//上传头像
				ExtDics: [], //业务员列表
				sales: "", //业务员
				usetype: false, //隐藏业务员
				loading: true,
				msg: "",
				input1: "",
				mark5: false,
				qxlist: [],
				qxpz: {
					login: ""
				},
				mark4: false,
				formInline: { //密码
					pwd: '',
					oldpwd: ''
				},
				Mark3: false,
				authlist: [],
				roleList: [],
				role: "",
				Mark2: false,
				radio: '1',
				leng: 1,
				form: {
					name: '',
					pass: '',
					tel: '',
					pwd: "",
					username: "",
				},
				tableData: [],//用户列表
				currentRow: null,
				dialogVisible: false,
				login: "", //登入名
				id: "", //id
				type: "", //类型
				stadu: "", //状态
				imgUrl:"",
				pageindex:0,
			}
		},
		created() {
			this.host = api.files
			this.getuserlist();
		},
		updated: function() {
			this.$nextTick(function() {
				//点击添加样式
				var list = document.getElementsByClassName("list-group-item");
				for(var i = 0; i < list.length; i++) {
					list[i].onclick = function() {
						for(var j = 0; j < list.length; j++) {
							list[j].className = "list-group-item"
						}
						this.className = "list-group-item act"
					}
				};
			});
		},
		computed: {
			//过滤
//			newTableLi() {
//				return this.tableData.filter((tableData) => {
//					return tableData.Login.toLowerCase().indexOf(this.msg.toLowerCase()) !== -1
//				})
//			}
		},
		methods: {
			submitUpload() {
				this.host = api.files
		        this.$refs.upload.submit();
		    },
		    uploadSuccess(response, file, fileList){
		    	this.$message({
					message: '上传成功',
					type: 'success'
				});
		    	console.log('上传文件', response)
		    	this.imgUrl = response.data.filePaht.substring(2, response.data.filePaht.length)
		    },
		    uploadError (response, file, fileList){
		    },
		    handleRemove(file, fileList) {
		    },
		    handlePreview(file) {
		    },
		     //点击翻页
			handleCurrentChange(val) {
				this.loading = true
				this.pageindex = val
				this.$axios.post(api.getuserlist,{
					  "Para": this.input1,
					  "PageSize": 10,
					  "PageIndex": this.pageindex-1,
					  "OrderbyString": "CNName"
				}).then((res) => {
					if(res.data.isOK) {
						this.tableData = res.data.data.Data
						this.leng = res.data.data.Items
						this.loading = false
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				}).catch(function(res) {
					console.log(res);
				})
			},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						this.formInline.oldpwd = "";
						this.formInline.pwd = "";
						this.form.username = "";
						this.form.pass = "";
						this.form.name = "";
						this.form.tel = "";
						this.form.pwd = ""
						this.role = ""
						done();
					})
					.catch(_ => {});
			},
			//搜索
			searcj(){
				console.log(this.input1)
				this.$axios.post(api.getuserlist,{
					  "Para": this.input1,
					  "PageSize": 10,
					  "PageIndex": 0,
					  "OrderbyString": "CNName"
				}).then((res) => {
					if(res.data.isOK) {
						this.tableData = res.data.data.Data
						this.leng = res.data.data.Items
						this.loading = false
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				}).catch(function(res) {
				})
			},
			//删除用户
			deleteRow(index, name) {
				this.loading = true;
				this.$axios.get(api.deluser + '/' + name, ).then((res) => {
					if(res.data.isOK) {
						this.loading = false;
						this.getuserlist()
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//修改操作用户弹框
			modify: function(type, name, login, str, tel,BuisnessID) {
				this.saleslist()
				this.mark5 = true;
				this.form.name = name;
				this.form.username = login;
				this.form.tel = tel;
				this.radio = type.toString();
				this.stadu = str;
				this.chang()
				this.sales=BuisnessID
			},
			//修改用户数据
			updateuser() {
				this.loading = true,
					this.$axios.post(api.updateuser, {
						"LoginType": this.radio,
						"ID": "1",
						"Login": this.form.username,
						"Pwd": md5(this.form.pass),
						"CNName": this.form.name,
						"ErrCount": "5",
						"Tel": this.form.tel,
						"Status": this.stadu,
						"BusinessID": this.sales,
						"openID": "",
						"Token": localStorage.token,
						"Memo": "",
						"CreateMan": "",
						"CreateDate": "",
						"HeadIMG":this.imgUrl,
					}).then((res) => {
						if(res.data.isOK) {
							this.loading = false,
								this.$message({
									message: '修改成功',
									type: 'success'
								});
							this.form.username = "";
							this.form.pass = "";
							this.form.name = "";
							this.form.tel = "";
							this.form.pwd = ""
							this.getuserlist()
							this.mark5 = false
						} else {
							if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
								this.$router.push({
									path: '/login'
								})
							} else {
								this.loading = false
								this.$message.error(res.data.msg);
							}
						}
					});
			},
			//获取操作员列表
			getuserlist() {
				this.loading = true
				this.pageindex = 0
				this.$axios.post(api.getuserlist,{
					  "Para": "",
					  "PageSize": 10,
					  "PageIndex": this.pageindex,
					  "OrderbyString": "CNName"
				}).then((res) => {
					if(res.data.isOK) {
						this.tableData = res.data.data.Data
						this.leng = res.data.data.Items
						this.loading = false
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				}).catch(function(res) {
					console.log(res);
				})
			},
			//新建用户弹框
			addust(){
				this.saleslist()
				this.sales=""
				this.formInline.oldpwd = "";
				this.formInline.pwd = "";
				this.form.username = "";
				this.form.pass = "";
				this.form.name = "";
				this.form.tel = "";
				this.form.pwd = ""
				this.role = ""
				this.dialogVisible = true;
				this.radio="1";
				this.chang()
			},
			//新建用户
			newUere() {
				this.loading = true
				this.$axios.post(api.adduser, {
					"LoginType": this.radio,
					"ID": "",
					"Login": this.form.username,
					"Pwd": md5(this.form.pass),
					"CNName": this.form.name,
					"ErrCount": "",
					"Tel": this.form.tel,
					"Status": "",
					"BusinessID": this.sales,
					"openID": "",
					"Token": "",
					"Memo": "",
					"CreateMan": "",
					"CreateDate": "",
					"HeadIMG":this.imgUrl,
				}).then((res) => {
					if(res.data.isOK) {
						this.loading = false
						this.$message({
							message: '创建成功',
							type: 'success'
						});
						this.setrole(this.form.username)
						this.form.username = "";
						this.form.pass = "";
						this.form.name = "";
						this.form.tel = "";
						this.form.pwd = ""
						this.radio = '1'
						this.getuserlist();
						this.dialogVisible = false;				
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//取消添加操作员
			quxia() {
				this.form.username = "";
				this.form.pass = "";
				this.form.name = "";
				this.form.tel = "";
				this.form.pwd = "";
				this.formInline.oldpwd = "";
				this.radio = '1'
				this.formInline.pwd = "";
				this.dialogVisible = false;
				this.mark5 = false
				this.Mark3 = false
			},
			//锁定用户
			lock(index, name, Status) {
				//锁用户
				this.loading = true
				if(Status) {
					this.$axios.get(api.unlock + '/' + name, {
						headers: {
							token: localStorage.token
						}
					}, ).then((res) => {
						if(res.data.isOK) {
							this.loading = false
							this.getuserlist()
						} else {
							if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
								this.$router.push({
									path: '/login'
								})
							} else {
								this.loading = false
								this.$message.error(res.data.msg);
							}
						}
					});
				} else {
					//锁定用户
					this.$axios.get(api.lock + '/' + name, {
						headers: {
							token: localStorage.token
						}
					}, ).then((res) => {
						if(res.data.isOK) {
							this.getuserlist()
						} else {
							if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
								this.$router.push({
									path: '/login'
								})
							} else {
								this.loading = false
								this.$message.error(res.data.msg);
							}
						}
					});
				}

			},
			//添加角色
			addrol() {
				this.role = ""
				this.Mark2 = true;
				this.userroles()
			},
			//获取所有角色信息
			getrolelist() {
				this.$axios.get(api.getrolelist).then((res) => {
					if(res.data.isOK) {}
				});
			},
			//获取角色列表1
			userroles() {
				this.loading = true
				var me = this
				var login = localStorage.login
				this.$axios.get(api.userroles + "/" + login).then((res) => {
					if(res.data.isOK) {
						this.loading = false
						res.data.data.RoleList = res.data.data.RoleList ? res.data.data.RoleList : [{}]
						this.roleList = res.data.data.RoleList
						setTimeout(function() {
							$("#jiaose button").eq(0).addClass("act").siblings().removeClass("act")
							this.id = $("#jiaose button").eq(0).val()
							if(this.id){
								me.fnJur(this.id)
							}
						}, 0)
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//获取角色列表2
			userrolesass() {
				this.loading = true
				var me = this
				var login = this.qxpz.login
				console.log(login)
				this.$axios.get(api.userroles + "/" + login).then((res) => {
					if(res.data.isOK) {
						this.loading = false
						res.data.data.RoleList = res.data.data.RoleList ? res.data.data.RoleList : [{}]
						this.roleList = res.data.data.RoleList
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//新建角色
			addRole() {
				this.loading = true
				this.$axios.post(api.addrole, {
					"ID": "",
					"RoleName": this.role,
					"Memo": "",
					"CreateMan": "",
					"CreateDate": ""
				}).then((res) => {
					if(res.data.isOK) {
						this.loading = false
						this.$message({
							message: '新建成功',
							type: 'success'
						});
						this.userroles()
						this.role = ""
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//点击角色显示权限列表
			fnJur(id) {
				this.loading = true
				var me = this
				this.id = id
				console.log(this.id)
				this.$axios.get(api.authlist + '/' + id).then((res) => {
					if(res.data.isOK) {
						this.loading = false
						res.data.data = res.data.data ? res.data.data : [{}]
						me.authlist = res.data.data
						console.log(me.authlist)
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//权限配置
			autl() {
				this.loading = true
				var id = this.id
				var me = this
				var RoleIDList = new Array();
				$('input[name="check"]:checked').each(function() {
					RoleIDList.push($(this).val()); //向数组中添加元素  
				});
				this.$axios.post(api.setauth, {
					"RoleID": id,
					"AuthIDList": RoleIDList
				}).then((res) => {
					if(res.data.isOK) {
						this.loading = false
						res.data.data = res.data.data ? res.data.data : [{}]
						me.authlist = res.data.data
						this.Mark2 = false;

					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//取消新建弹框
			Mark() {
				this.role = "";
				this.Mark2 = false
			},
			//修改密码弹框
			fnReset(login) {
				this.Mark3 = true;
				this.login = login
			},
			//确定修改密码
			ModiPwd() {
				this.loading = true
				if(this.formInline.oldpwd == this.formInline.pwd && this.formInline.oldpwd != null) {
					this.$axios.post(api.changepwd, {
						"Login": this.login,
						"NewPwd": md5(this.formInline.oldpwd),
						"OldPwd": "",
						"ValidOld": false
					}).then((res) => {
						if(res.data.isOK) {
							this.loading = false
							this.$message({
								message: '修改成功',
								type: 'success'
							});
							this.getuserlist();
							this.Mark3 = false;
							this.formInline.oldpwd = "";
							this.formInline.pwd = "";
						} else {
							if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
								this.$router.push({
									path: '/login'
								})
							} else {
								this.loading = false
								this.$message.error(res.data.msg);
							}
						}
					});
				} else {
					this.loading = false
					this.$message.error("两次密码输入不一样");
					this.Mark3 = true;
				}

			},
			//删除角色
			delUse() {
				if(this.roleList.length>0){
					this.loading = true
					this.$axios.get(api.delrole + '/' + this.id, {
						headers: {
							token: localStorage.token
						}
					}, ).then((res) => {
						if(res.data.isOK) {
							this.loading = false
							this.$message({
								message: '删除成功',
								type: 'success'
							});
							this.userroles()
							if(this.roleList.length==1){
								this.authlist=[]
							}
						} else {
							if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
								this.$router.push({
									path: '/login'
								})
							} else {
								this.loading = false
								this.$message.error(res.data.msg);
							}
						}
					});
				}
			},
			//为用户设置权限
			setrole(nanm) {
				this.qxpz.login = nanm;
				this.userrolesass();
				this.mark4 = true
			},
			//取消
			fnCancel() {
				this.mark4 = false
			},
			//提交用户角色
			fnSubRole() {
				console.log(this.qxpz.login)
				this.loading = true
				var RoleIDList = new Array();
				$('input[name="row"]:checked').each(function() {
					RoleIDList.push(($(this).val() - 0)); //向数组中添加元素  
				});
				this.$axios.post(api.setrole, {
					"Login": this.qxpz.login,
					"RoleIDList": RoleIDList
				}).then((res) => {
					if(res.data.isOK) {
						this.loading = false
						this.$message({
							message: '提交成功',
							type: 'success'
						});
						this.userrolesass();
						this.mark4 = false
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/login'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			},
			//取消用户openID绑定
			Unbundling(index, name) {
				this.loading = true
				this.$axios.get(api.Unbundling + '/' + name).then((res) => {
					console.log(res)
					if(res.data.isOK) {
						this.loading = false
						this.$message({
							message: '解绑成功',
							type: 'success'
						});
					} else {
							if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
								this.$router.push({
									path: '/login'
								})
							} else {
								this.loading = false
								this.$message.error(res.data.msg);
							}
						}
					}
				)
			},
			//添加
			add() {
				this.msg = this.input1;
			},
			//显示隐藏业务员
			chang() {
				if(this.radio==2){
					this.usetype=true			
				}else{
//					this.ExtDics=[];
					this.sales=""
					this.usetype=false
				}
			},
			//获取业务员列表
			saleslist() {
				var me = this
				me.$axios.post(api.salesgetlist, {
					"Para": {
						"ParendID": "",
						"Key": ""
					},
					"PageSize": 10000,
					"PageIndex": 0,
					"OrderbyString": "CNName"
				}).then((res) => {
					if(res.data.isOK) {
						for(var i = 0; i < res.data.data.Data.length; i++) {
							me.ExtDics.push({
								value: res.data.data.Data[i].ID,
								lable: res.data.data.Data[i].CNName
							})
						}
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
								this.$router.push({
									path: '/login'
								})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				});
			}
		}
	}
</script>

<style scoped>
	.title1 {
		text-indent: 20px;
		width: 100%;
		padding: 15px 0;
		background: #fff;
		border-bottom: 1px solid #dddee1;
	}
	
	.title1 span {
		margin-right: 10px;
		
	}
	
	.title1 .h1 {
		font-size: 16px;
		font-weight: 600;
	}
	
	.title1 .h2 {
		font-size: 14px;
	}
	
	.con {
		width: 100%;
		box-sizing: border-box;
	}
	
	.search {
		height: auto;
		width: 100%;
		/*border: 1px solid #000;*/
	}
	
	.search button {
		margin: 10px;
	}
	
	.page {
		float: right;
		margin-top: 20px;
	}
	
	.el-dropdown-menu__item {
		text-align: center;
	}
	
	.el-dropdown-menu {
		min-width: 79px !important;
	}
	
	.rowl {
		color: #fff;
		background-color: #5d9cec;
		border-color: #cfdbe2;
		padding: 10px 0;
		text-indent: 15px;
	}
	
	.list-group-item {
		position: relative;
		display: block;
		padding: 10px 0px;
		text-align: left;
		text-indent: 15px;
		margin-bottom: -1px;
		background-color: #fff;
		border: 1px solid #e4eaec;
		width: 100%;
		cursor: pointer;
	}
	
	.qxleft {
		border: 1px solid #cfdbe2;
	}
	
	.panel {
		border: 1px solid #cfdbe2;
		padding: 10px;
		box-sizing: border-box;
	}
	
	.qxtop {
		height: 36px;
		line-height: 36px;
		margin-bottom: 15px;
	}
	
	.qxtype {
		border: 1px solid #cfdbe2;
		border-color: #cfdbe2;
		border-top-width: 3px;
		margin-bottom: 21px;
		background-color: #fff;
		border-radius: 4px;
		-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
		box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
		padding: 10px;
	}
	
	.qxtype-title {
		color: #444;
		background-color: #fff;
		border-color: #cfdbe2;
		border-bottom: 0;
		font-size: 14px;
		padding: 10px 15px;
		border-bottom: 1px solid transparent;
		border-top-right-radius: 3px;
		border-top-left-radius: 3px;
	}
	
	.qxtype>div {
		padding: 15px;
		margin-bottom: 21px;
		background-color: #fff;
		border: 1px solid transparent;
		border-radius: 4px;
		-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
		box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
		border-top-width: 3px;
		border-color: #cfdbe2;
	}
	
	.el-dialog__footer {
		text-align: center;
	}
	
	.act {
		background-color: #B9C4D1!important;
	}
	
	.qxpzbox {
		max-height: 240px;
		overflow: auto;
		border: 1px solid #cfdbe2;
		border-top-width: 3px;
		border-color: #cfdbe2;
		margin-bottom: 21px;
		background-color: #fff;
		border-radius: 4px;
		-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
		box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
		padding: 15px;
	}
	
	.qx-title {
		margin-bottom: 15px;
	}
	
	.check {
		vertical-align: middle;
		margin-right: 5px;
		width: 15px;
		height: 15px;
	}
	
	.mark1 {
		position: fixed;
		background: rgba(0, 0, 0, .5);
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	
	.mark2 {
		position: fixed;
		background: rgba(0, 0, 0, .5);
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	
	.mark4 {
		position: fixed;
		background: rgba(0, 0, 0, .5);
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	
	.mark3 {
		position: fixed;
		background: rgba(0, 0, 0, .5);
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	
	.mark5 {
		position: fixed;
		background: rgba(0, 0, 0, .5);
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	
	.el-table::before {
		height: 0 !important;
	}
	
	.clearfix:after {
		display: block;
		clear: both;
		content: "";
		visibility: hidden;
		height: 0
	}
	.el-col{
		margin-right: 0px !important;
	}
	.divlist{
		display: inline-block;
		margin-left: 10px;
	}
</style>